package LW.org.action;

import LW.org.model.Admin;
import LW.org.service.userServicelogin;
import LW.org.serviceImple.userServiceLoginImple;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

import java.util.Map;

@Controller("userloginAction")
public class userloginAction extends ActionSupport {

    private int id;
    private String password;
    @Autowired
    @Qualifier("userServiceLoginImple")
    private userServicelogin userservicelogin;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String login() throws Exception {
        boolean realuser = userservicelogin.check_out(this.id, this.password);
        if (realuser) {
            Admin templateOne = userservicelogin.find_one(this.id);
            Map<String, Object> session = ActionContext.getContext().getSession();
            session.put("loginstatus", true);
            session.put("currentAdmin",templateOne);
            return SUCCESS;
        } else {
            Map<String, Object> session = ActionContext.getContext().getSession();
            session.put("errormessage", "账户不存在或密码错误");
            return ERROR;
        }
    }


}
